package chapter06.s02set.p03treeset.e13;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * treeSet
 * 自定义 compareTo
 * 2：  TreeSet(java.util.Comparator<? super E> comparator)
 */
class Student {
    private String id;
    private String name;

    public Student(String id, String name) {
        this.id = id;
        this.name = name;
    }

    // 重写toString()方法
    public String toString() {
        return id + ":" + name;
    }
}

public class Example13 {
    public static void main(String[] args) {
        TreeSet ts = new TreeSet(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                return -1;
            }
        });
        ts.add(new Student("1", "张三"));
        ts.add(new Student("2", "李四"));
        ts.add(new Student("2", "王五"));
        System.out.println(ts);
    }
}
